//队列加载图片
function laterLoadImg(className,setIntervalTime){
	var arr=[];
	setIntervalTime=setIntervalTime&&500;
	$('.'+className+'-src').each(function(){
		var $this=$(this);
		var url=$this.attr('data-src');
		arr.push({target:$this,url:url,type:1});
	});
	$('.'+className+'-bak').each(function(){
		var $this=$(this);
		var url=$this.attr('data-src');
		arr.push({target:$this,url:url,type:2});
	});
	function loadImg(){
		var arrTem=arr.shift();
		if(!arrTem){
			clearInterval(setIntervalIndex);
			return;
		}
		var $target=arrTem.target;
		var type=arrTem.type;
		var url=arrTem.url;
		if(type==1){
			$target.attr("src",url);
		}else{
			$target.css("background-image","url("+url+")");
		}
		
	}
	function reset(){
		//如果不能调用setInterval
		$.each(arr,function(index,arrTem){
			var $target=arrTem.target;
			var type=arrTem.type;
			var url=arrTem.url;
			if(type==1){
				$target.attr("src",url);
			}else{
				$target.css("background-image","url("+url+")");
			}
		});
	}
	if(!setInterval){
		reset();
		return false;
	}
	var setIntervalIndex=setInterval(loadImg,setIntervalTime);
}


(function(window) {
	function General() {}
		//特殊字符
	General.specialString = "null###yedadou###null";
	//-----------------遮罩-----------------

	//用于保存遮罩层
	General.maskBg = null;
	General.loadingBg = null;

	/**
	 * 判断是否微信浏览器
	 */
	General.isWeixin = function() {
		var u = navigator.userAgent;
		var ua = u.toLowerCase();
		if (ua.match(/MicroMessenger/i) == "micromessenger") {
			return true;
		} else {
			//如果安桌，还是要显示
			var isAndroid=u.indexOf('Android') > -1;
			if(isAndroid) return true;
			return false;
		}
	}

	/**
	 * 检查是否微信浏览器,如果是微信浏览器则隐藏标题
	 */
	General.CheckIsWeixin = function() {
		if (General.isWeixin()) {
			try {
				$("header").hide();
				$("body").addClass("body-background-position-top"); //去掉头文件背景的位置向上移
				$("body").addClass("weixin-browser");
			} catch (e) {

			}
		}
	}

	/**
	 * 显示遮罩
	 */
	General.showMask = function() {
		try {
			if (General.maskBg == null) {
				var str = "<div class='mask-bg'></div>";
				General.maskBg = $(str).appendTo($("body"));
			}
			General.maskBg.show();
		} catch (e) {
			//			Common.log(e);
		}
	}

	/**
	 * 显示遮罩
	 */
	General.hideMask = function() {
		try {
			if (General.maskBg != null) {
				General.maskBg.hide();
			}
		} catch (e) {
			//			Common.log(e);
		}
	}

	/**
	 * 显示加载提示
	 */
	General.showLoading = function(info) {
		try {
			if (General.loadingBg == null) {
				var str = "<div class='mask-bg'><div class='mask-wrapper'><span class='mask-animation'><i class='fa fa-spinner fa-spin fa-lg'></i></span><div class='mask-tip hide'></div></div></div>";
				General.loadingBg = $(str).appendTo($("body"));
			}
			General.loadingBg.show();
			if (info != undefined && info != null) {
				General.loadingBg.find(".mask-tip").removeClass("hide").html(info);

				//				Common.showLoading(info);
			} else {
				General.loadingBg.find(".mask-tip").addClass("hide").html("");
			}
			var maskWrapper = General.loadingBg.find(".mask-wrapper");
			var w = maskWrapper.width() / 2;
			var h = maskWrapper.height() / 2;
			maskWrapper.css({
				"margin-left": -w + "px",
				"margin-top": -h + "px"
			});
			//计算
		} catch (e) {
			//			Common.log(e);
		}
	}

	/**
	 * 隐藏加载提示
	 */
	General.hideLoading = function() {
		try {
			if (General.loadingBg != null) {
				General.loadingBg.hide();
			}
		} catch (e) {
			//			Common.log(e);
		}
	}

	//-----------------停止事件冒泡-----------------
	/**
	 * 停止事件冒泡
	 * @param {Object} e 事件
	 */
	General.stopEvent = function(e) {
		e.stopImmediatePropagation();
		e.stopPropagation();
		e.preventDefault();
	}

	//-----------------关闭编辑窗口-----------------
	/**
	 * 关闭编辑窗口
	 * @param {Object} options 用作扩展用
	 */
	General.closeEditWindow = function(options, dialogId) {
		if (dialogId == undefined || dialogId == null)
			$("#dialog-edit").dialog("close");
		else
			$("#" + dialogId).dialog("close");
	}

	//-----------------表格中的复选框操作-----------------
	/**
	 * 初始化表格中的复选框事件监听
	 */
	General.initCheckbox = function() {
		//点击"全选"复选框
		$("#check-all").on("click", function(e) {
			$('input[type=checkbox][name=check-row]').prop('checked', $(this).prop('checked'));
			General.updateCheckedIds();
		});
		$("input[type=checkbox][name=check-row]").on("click", function(e) {
			General.updateCheckedIds();
		});
		try {
			if ($("#addToGroup").length > 0) {
				$("#addToGroup").attr("disabled", "disabled");
			}
		} catch (e) {
			Common.log(e);
		}
	}
	/**
	 * 更新已被选中的行ID
	 */
	General.updateCheckedIds = function() {
		var ids = [];
		var id;
		$('input[type=checkbox][name=check-row]:checked').each(function(index, element) {
			id = $(this).closest("tr").attr("data-id");
			ids.push(id);
		});
		try {
			if ($("#addToGroup").length > 0) {
				if (ids.length > 0) {
					$("#addToGroup").removeAttr("disabled");
				} else {
					$("#addToGroup").attr("disabled", "disabled");
				}
			}
		} catch (e) {
			Common.log(e);
		}
		$("#checkedIds").val(ids.join(","));
	}

	//-----------------扩展对话框-----------------
	General.hasExtendDialogTitle = false;
	/**
	 * 扩展对话框
	 */
	General.extendDialog = function() {
		General.hasExtendDialogTitle = true;
		$.widget("ui.dialog", $.extend({}, $.ui.dialog.prototype, {
			_title: function(title) {
				var $title = this.options.title || ' '
				if (("title_html" in this.options) && this.options.title_html == true)
					title.html($title);
				else title.text($title);
			}
		}));
	}

	//-----------------ifame加载-----------------
	/**
	 * 是否已经注册过加载事件(true:已注册 false:未注册)
	 */
	General.isInitLoadIframe = false;
	/**
	 * 对话框中的iframe的ID
	 */
	General.dialogIframeId = "top-container";

	/**
	 * 弹出窗口的ID
	 */
	General.dialogId = "modalDialog";

	/**
	 * 调节弹出窗口的高度
	 */
	General.isAdjustDialogHeight = false;

	/**
	 * 注册ifame加载完成事件
	 * @param {String} dialogIframeId iframe的ID
	 * @param {Function} completeFunction iframe中的页面加载完成后执行的操作
	 */
	General.initLoadIframe = function(dialogIframeId, completeFunction) {
		General.isInitLoadIframe = true;
		try {
			//			
			var oFrm = document.getElementById(dialogIframeId);
			if (oFrm.onreadystatechange != undefined) {
				oFrm.onreadystatechange = function() {
					if (this.readyState && this.readyState != 'complete') return;
					else
						completeFunction();
				}
			} else {
				oFrm.onload = function() {
					if (this.readyState && this.readyState != 'complete') return;
					else
						completeFunction();
				}
			}
		} catch (e) {
			Common.log(e);
		}
	}

	/**
	 * 显示url地址对应的页面
	 * @param {String} url 网页地址
	 */
	General.showIframePage = function(url) {
		//监听点击事件
		if (url != "" && url != "#") {
			//链接不为空
			url = Common.addUrlParameters(url, {
				"dt": Math.random() + ""
			});
			$("#" + General.dialogIframeId).attr("src", url);
			General.showIframeLoading();
			if (!General.isInitLoadIframe)
				General.initLoadIframe(General.dialogIframeId, General.hideIframeLoading);
		}
	};

	/**
	 * 获取iframe页面中内容的高度
	 */
	General.getIframeHeight = function() {
		var result = 0;
		try {
			var iframe = document.getElementById(General.dialogIframeId);
			if (iframe.attachEvent) {
				result = iframe.contentWindow.document.documentElement.scrollHeight;
			} else {
				result = iframe.contentDocument.body.scrollHeight;
			}
		} catch (e) {

		}
		return result;
	}

	/**
	 * 调节iframe的高度以适应内容的高度
	 */
	General.adjustDialogHeight = function() {
		var maxPercent = 0.92; //最大高度百分比
		var widgetHeight = 90; //要减去的高度
		var innerHeight = General.getIframeHeight();
		var maxHeight = $(window).height() * maxPercent; //获取窗口的高度
		var currentHeight = $("#" + General.dialogId).dialog("option", "height"); //当前高度
		innerHeight += widgetHeight;

		console.log(innerHeight, currentHeight, maxHeight)
			//		if(innerHeight<currentHeight){
			//			$("#" + General.dialogId).dialog("option", "height", innerHeight);
			//		}else {
		if (innerHeight < maxHeight) {
			$("#" + General.dialogId).dialog("option", "height", innerHeight);
		} else {
			$("#" + General.dialogId).dialog("option", "height", maxHeight);
		}
		//		}
	}

	/**
	 * 隐藏页面的加载状态(用于iframe中加载页面)
	 */
	General.hideIframeLoading = function() {
		$("#" + General.dialogIframeId).siblings(".loading-bg").addClass("hide");
		//调节iframe的高度
		if (General.isAdjustDialogHeight) {
			General.adjustDialogHeight();
		}
	};

	/**
	 * 显示页面的加载状态(用于iframe中加载页面)
	 */
	General.showIframeLoading = function() {
		$("#" + General.dialogIframeId).siblings(".loading-bg").removeClass("hide");
	};

	/**
	 * 隐藏页面的加载状态(用于在当前页面中通过ajax加载数据)
	 */
	General.hideDialogLoading = function() {
		$("#dialog-edit .loading-bg").addClass("hide");
		$("#dialog-edit").siblings(".ui-dialog-buttonpane").find("button").removeAttr("disabled");
	};

	/**
	 * 显示页面的加载状态(用于在当前页面中通过ajax加载数据)
	 */
	General.showDialogLoading = function(options) {
		if ($("#dialog-edit .loading-bg").length <= 0) {
			var loadingDiv = '<div class="loading-bg"><div class="loading-animation"><i class="fa fa-spinner fa-spin"></i></div></div>';
			$(loadingDiv).appendTo("#dialog-edit");
		}
		$("#dialog-edit .loading-bg").removeClass("hide");
		//默认禁用所有按钮,如果设置disableButton参数则只禁用disableButton指定的按钮
		if (options && options.disableButton) {
			$("#dialog-edit").siblings(".ui-dialog-buttonpane").find(options.disableButton).attr("disabled", "disabled");
		} else {
			$("#dialog-edit").siblings(".ui-dialog-buttonpane").find("button").attr("disabled", "disabled");
		}
	};

	/**
	 * 关闭弹出窗口
	 */
	General.closeWindow = function(selector) {
		try {
			if (selector)
				$(selector).dialog("close");
			else
				General.closeDialog();
		} catch (e) {
			try {
				General.closeDialog();
			} catch (e2) {}
		}
	};

	/**
	 * 关闭弹出窗口并刷新当前页面
	 */
	General.closeAndRefresh = function(selector) {
		General.closeWindow(selector);
		window.location.reload();
	};

	/**
	 * 关闭弹出窗口
	 */
	General.closeDialog = function() {
		General.closeWindow("#" + General.dialogId);
	};

	/**
	 * 显示弹出窗口
	 * @param {String} title 弹出窗口的标题
	 * @param {String} url 页面地址
	 */
	General.showDialog = function(title, url) {
		var height = $(window).height(); //获取窗口的高度
		height = height * 0.9;
		$("#" + General.dialogId).removeClass('hide').dialog({
			resizable: false,
			width: '90%',
			height: height,
			modal: true,
			closeText: "关闭",
			title: "<div class='widget-header'><h4 class='smaller'> " + title + "</h4></div>",
			title_html: true,
			buttons: []
		});
		General.showIframePage(url);
	}

	/**
	 * 显示弹出窗口(使用宽度和高度)
	 * @param {String} title 弹出窗口的标题
	 * @param {String} url 页面地址
	 * @param {Number} width 对话框宽度
	 * @param {Number} height 对话框高度(如果高度设置为0表示采用当前页面90%高度)
	 */
	General.showDialogWidthHeight = function(title, url, width, height) {
		if (height == 0) {
			height = $(window).height(); //获取窗口的高度
			height = height * 0.9;
		}
		$("#" + General.dialogId).removeClass('hide').dialog({
			resizable: false,
			width: width,
			height: height,
			modal: true,
			closeText: "关闭",
			title: "<div class='widget-header'><h4 class='smaller'> " + title + "</h4></div>",
			title_html: true,
			buttons: []
		});
		General.showIframePage(url);
	}

	/**
	 * 显示弹出窗口(有关闭按钮,使用宽度和高度)
	 * @param {String} title 弹出窗口的标题
	 * @param {String} url 页面地址
	 * @param {Number} width 对话框宽度
	 * @param {Number} height 对话框高度(如果高度设置为0表示采用当前页面90%高度)
	 */
	General.showDialogWidthHeightClose = function(title, url, width, height) {
		General.isAdjustDialogHeight = true;
		if (height == 0) {
			height = $(window).height(); //获取窗口的高度
			height = height * 0.9;
		}
		$("#" + General.dialogId).removeClass('hide').dialog({
			resizable: false,
			width: width,
			height: height,
			modal: true,
			closeText: "关闭",
			title: "<div class='widget-header'><h4 class='smaller'> " + title + "</h4></div>",
			title_html: true,
			buttons: [{
				html: "<i class='ace-icon fa fa-times'></i> 关闭",
				"class": "btn btn-danger btn-minier",
				click: function() {
					$(this).dialog("close");
				}
			}]
		});
		General.showIframePage(url);
	}

	/**
	 * 刷新页面
	 */
	General.refresh = function() {
		window.location.reload();
	};

	/**
	 * 初始化页面中所有自动跳转的下拉列表,切换值时自动跳转到相应的url,如果值为#则不跳转
	 * @param {String} selector 选择器
	 */
	General.initAutoPostSelect = function(selector) {
		if (selector == undefined || selector == null)
			selector = "select.auto-jump";
		$(selector).on('change', function(e) {
			var url = $(this).find("option:selected").attr("data-href");
			if (url != "#" && url != "") {
				//判断是否有附加参数
				var ids = $(this).attr("data-addition");
				if (ids) {
					var obj;
					$.each(ids.split(","), function(index, value) {
						obj = {};
						var key = value;
						if (value.indexOf("#") == 0) {
							key = value.replace("#", "");
						} else if (value.indexOf(".") == 0) {
							key = value.replace(".", "");
						}
						obj[key] = General.getValue(value);
						url = Common.addUrlParameters(url, obj);
					});
				}
				window.location.href = url;
			}
		});
	};

	/**
	 * 获取选择器对应的值
	 * @param {String} selector 选择器
	 */
	General.getValue = function(selector) {
		//判断选择符是否以"#或.开始"
		if (selector.indexOf("#") != 0) {
			selector = "#" + selector;
		}
		var type = "value"; //设置值的方式
		var tagName = $(selector)[0].tagName.toLowerCase();
		if (tagName != "input") {
			type = "html";
		}
		//获取初始值
		var result = "";
		if (type == "value") {
			result = $(selector).val();
		} else {
			result = $(selector).html();
		}
		return result;
	};
	
	/**
	 * 设置选择器对应的值
	 * @param {String} selector 选择器
	 * @param {String} value 值
	 */
	General.setValue = function(selector,value) {
		//判断选择符是否以"#或.开始"
		if (selector.indexOf("#") != 0) {
			selector = "#" + selector;
		}
		var type = "value"; //设置值的方式
		var tagName = $(selector)[0].tagName.toLowerCase();
		if (tagName != "input") {
			type = "html";
		}
		if (type == "value") {
			$(selector).val(value);
		} else {
			$(selector).html(value);
		}
	};
	
	/**
	 * 弹出服务器提示
	 * @param {String} msg 服务器提示
	 * @param {String} url 点确定后要跳转的地址,为空则不进行操作
	 * @param {Object} win 当前窗口
	 * @param {Object} data 返回的数据(经过转换的json格式){"success":true,"msg":"成功","sub_msg":"","url":""}
	 */
	General.showServerMessage = function(msg, url, win, data) {
		var obj = {
			win: win,
			url: url,
			data: data
		};
		//		console.log(data["successFun"])
		General.alert(msg, null, General.goto, obj);
	};

	/**
	 * 跳转到相应的页面
	 * @param {Object} obj
	 */
	General.goto = function(obj) {
		//		try {
		if (obj.data["success"] && obj.data["successFun"]) {
			//				console.log(obj.data["successFun"])
			if (obj.data["successParam"]) {
				obj.data["successFun"](obj.data);
			} else {
				obj.data["successFun"]();
			}
		}
		//		} catch (e) {}
		if (obj.url) {
			if (obj.win)
				obj.win.location.href = obj.url;
			else
				window.location.href = obj.url;
		};
	};
	
	/**
	 * 显示当前页
	 * @param {Object} obj
	 */
	General.showCurrentPage = function(data) {
		var params=data["successParam"];
		var target=params.target;
		var pageTarget=params.pageTarget;
		data=data.data;
		if(data.length<=0){
			$(target).addClass("hide");
			General.alert("没有更多数据了...");
		}else{
			pageTarget=$(pageTarget).children("tbody");
			//开始分页
			$.each(data,function (index,row) {
				var tr=$("<tr></tr>").appendTo(pageTarget);
				$.each(row,function (i,str) {
					$("<td></td>").appendTo(tr).html(str);
				});
			});
			var fh=0;
			if($("footer").length>0){
				fh=$("footer").height();
			}
			fh+=15;
			var position=$(target).offset().top+$(target).height()+fh-$(window).height();
			$('html, body').animate({scrollTop:position}, 'fast'); 
//			$('html, body').animate({scrollTop:$(document).height()}, 'slow'); 
		}
	};
	
	window.showCurrentPage=General.showCurrentPage;
	//-----------------不同类型的对话框-----------------
	/**
	 * 弹出框
	 * @param {String} msg 弹出信息
	 * @param {String} title 标题
	 * @param {Function} okFun 点击确定后的操作
	 * @param {String} data 数据
	 */
	General.alert = function(msg, title, okFun, data) {
		if ($("#dialog-alert").length > 0) {
			$("#dialog-alert").remove();
		}
		var titleStr = "";
		if (!title) {
			title = "提示";
		}
		var str = "";
		str += "<div id='dialog-alert' class='modal' tabindex='-1' role='dialog' aria-labelledby='myModalLabel'><div class='modal-dialog' role='document'>";
		str += "<div class='modal-content'><div class='modal-header header-line'><h4 class='modal-title center'>" + title;
		str += "</h4></div><div class='modal-body center'>" + msg + "</div><div class='modal-footer center'>";
		str += "<button type='button' data-id='sure' class='button-yellow' data-dismiss='modal'>确定</button>";
		str += "</div></div></div></div>";

		$(str).appendTo($("body"));

		$("#dialog-alert").on('hidden.bs.modal', function(e) {
			if (okFun) {
				if (data)
					okFun(data);
				else
					okFun();
			}
		}).modal('show');
	};

	/**
	 * 确认框
	 * @param {String} msg 弹出信息
	 * @param {String} title 标题
	 * @param {Function} okFun 点击确定后的操作
	 * @param {Function} cancelFun 点击确定后的操作
	 * @param {String} data 数据
	 */
	General.confirm = function(msg, title, okFun, cancelFun, data) {
		if ($("#dialog-confirm").length > 0) {
			$("#dialog-confirm").remove();
		}
		var titleStr = "";
		if (!title) {
			title = "提示";
		}
		var str = "";
		str += "<div id='dialog-confirm' class='modal' tabindex='-1' role='dialog' aria-labelledby='myModalLabel'><div class='modal-dialog' role='document'>";
		str += "<div class='modal-content'><div class='modal-header header-line'><h4 class='modal-title center'>" + title;
		str += "</h4></div><div class='modal-body center'>" + msg + "</div><div class='modal-footer center'>";
		str += "<button type='button' data-id='sure' class='button-yellow' data-dismiss='modal'>确定</button>&nbsp;&nbsp;";
		str += "<button type='button' data-id='close' class='button-default' data-dismiss='modal'>取消</button>";
		str += "</div></div></div></div>";

		$(str).appendTo($("body"));

		$("#dialog-confirm button[data-id='sure']").click(function(e) {
			if (okFun) {
				if (data)
					okFun(data);
				else
					okFun();
			}
		});
		$("#dialog-confirm button[data-id='close']").click(function(e) {
			if (cancelFun) {
				if (data)
					cancelFun(data);
				else
					cancelFun();
			}
		});
		$("#dialog-confirm").modal('show');
	};

	/**
	 * 将form中的值转换为键值对
	 * @param {String} formSelector 表单选择
	 */
	General.getFormJson = function(formSelector) {
			var o = {};
			var a = $(formSelector).serializeArray();
			$.each(a, function() {
				if (o[this.name] !== undefined) {
					if (!o[this.name].push) {
						o[this.name] = [o[this.name]];
					}
					o[this.name].push(this.value || '');
				} else {
					o[this.name] = this.value || '';
				}
			});
			return o;
		}
		/**
		 * 判断数组中是否存在要查找的值
		 * @param {Array} arr 目标数组
		 * @param {String} str 要查找的字符串
		 */
	General.indexOf = function(arr, str) {
			var result = -1;
			$.each(arr, function(index, value) {
				if (value == str) {
					result = index;
					return false;
				}
			});
			return result;
		}
		//--------------------------------
	window.General = General;
	//--------------------------------
})(window);

(function(window) {
	function Common() {}

	//-----------------配置设置(START)-----------------

	//-----------------配置设置(END)-----------------

	//用于记录提示进度信息
	Common.tipId = null;

	//动画间隔时间(毫秒)
	Common.interval = 300;

	//动画当前步数
	Common.step = 0;

	//动画最大步数
	Common.maxStep = 6;
	//-----------------提示功能-----------------
	/**
	 * 开始动画
	 */
	Common.startAnimation = function() {
		Common.stopAnimation();
		Common.tipId = setInterval(Common.showCurrentStep, Common.interval);
	}

	/**
	 * 停止动画
	 */
	Common.stopAnimation = function() {
		if (Common.tipId != null) {
			clearInterval(Common.tipId);
			Common.tipId = null;
			Common.step = 0; //动画当前步数
			Common.showCurrentStep();
		}
	}

	/**
	 * 显示当前进度
	 */
	Common.showCurrentStep = function() {
		var sign = ".";
		var info = "";
		Common.step++;
		if (Common.step > Common.maxStep)
			Common.step = 0;
		for (var i = 0; i < Common.step; i++) {
			info += sign;
		}
		$("#operation-tip span:eq(1)").html(info);
	}

	/**
	 * 显示操作正在进行中的信息
	 * @param {String} info 提示信息
	 * @param {Object} options 用作扩展用
	 */
	Common.showLoading = function(info, options) {
		if (info == null) {

		} else {
			$("#operation-tip").removeClass('hide').find("span:eq(0)").html(info);
			Common.startAnimation();
		}
	}

	/**
	 * 隐藏操作正在进行中的信息
	 * @param {Object} options 用作扩展用
	 */
	Common.hideLoading = function(options) {
		Common.stopAnimation();
		$("#operation-tip").addClass('hide');
	}


	/**
	 * 关闭编辑窗口
	 * @param {Object} options 用作扩展用
	 */
	Common.closeEditWindow = function(options) {
		$("#dialog-edit").dialog("close");
	}

	//-----------------ajax-----------------
	/**
	 * ajax提交
	 * @param {Object} options 初始配置参数
	 * @param {Function} preAction 进行提交前的准备工作的函数
	 * @param {String} url 提交的地址
	 * @param {Object} data 提交的数据
	 * @param {String} tip 提示信息
	 * @param {Function} successFun 成功时运行的函数
	 * @param {Function} errorFun 失败时运行的函数
	 * @param {String} method 提交时的方法
	 * @param {Boolean} isHideLoading 是否隐藏加载动画(true:隐藏 false:显示)[默认显示加载动画]
	 */
	Common.ajaxPost = function(options, preAction, url, data, tip, successFun, errorFun, method, isHideLoading) {
		if (!isHideLoading) {
			General.showLoading(tip);
		}
		if (preAction != null) {
			preAction(options);
		}
		if (method) {

		} else {
			method = 'POST';
		}
		$.ajax({
			type: method,
			url: url,
			cache: false,
			data: data,
			success: function(data, status) {
				General.hideLoading();
				try {
					if (successFun != null)
						successFun(options, data, status);
				} catch (e) {}
			},
			error: function() {
				General.hideLoading();
				try {
					if (errorFun != null)
						errorFun(options);
					General.alert("操作失败,请检查网络连接");
				} catch (e) {}
			}
		});
	}

	/**
	 * ajax提交,根据服务器的返回值进行不同的操作
	 * @param {String} url 提交的地址
	 * @param {Object} data 提交的数据
	 * @param {String} tip 提交等待时的提示信息
	 * @param {Object} win 当前窗口
	 * @param {Object} maskWin 被遮罩的窗口
	 * @param {Boolean} isHideLoading 是否隐藏加载动画(true:隐藏 false:显示)[默认显示加载动画]
	 * @param {Function} successFun 成功时运行的函数
	 * @param {Object} successParam 成功时运行的函数所需的参数
	 * @param {Boolean} isHideResponse 不弹出框
	 */
	Common.ajaxPostWantResult = function(url, data, tip, win, maskWin, isHideLoading, successFun, successParam, isHideResponse) {
		var isError = false; //是否出现错误
		if (!isHideLoading) {
			General.showLoading(tip);
		}
		$.ajax({
			type: 'POST',
			url: url,
			cache: false,
			data: data,
			success: function(data, status) {
				try {
					if (maskWin)
						maskWin.General.hideMask();
				} catch (e2) {

				}
				General.hideLoading();
				try {
					data = $.parseJSON(data); //获取json格式的数据
				} catch (e) {
					isError = true;
				}
				if (!isError) {
					var msg = data["msg"] + (data["sub_msg"]||''); //提示
					if(parseInt(data["error"])==1){
						//如果明确为错误信息
						General.showServerMessage(msg,'', win, data); //弹出服务器执行结果
						return;
					}
					data["successFun"] = successFun;
					data["successParam"] = successParam;
					if (isHideResponse) {
						var obj = {
							win: win,
							url: data["url"],
							data: data
						};
						General.goto(obj);
					} else {
						General.showServerMessage(msg, data["url"], win, data); //弹出服务器执行结果
					}
				} else {
					General.alert("连接超时,请重试");
				}
			},
			error: function() {
				try {
					if (maskWin)
						maskWin.General.hideMask();
				} catch (e2) {

				}
				General.hideLoading();
				General.alert("操作失败,请检查网络连接");
			}
		});
	}

	/**
	 * 为url地址中添加参数
	 * @param {Object} url url地址
	 */
	Common.addUrlParameters = function(url, params) {
		try {
			var oldParams = Common.getUrlParameters(url);
			params = $.extend(oldParams, params);
			var urlParams = $.param(params); //生成新的参数
			//截取?号前的字符串
			var index = url.indexOf("?");
			if (index != -1) {
				url = url.substring(0, index);
			}
			url += "?" + urlParams;
		} catch (e) {
			Common.log(e);
		}
		return url;
	}

	/**
	 * 获取url地址中包含的参数
	 * @param {Object} url url地址
	 */
	Common.getUrlParameters = function(url) {
		var vars = {};
		try {
			var parts = url.replace(/[?&]+([^=&]+)=([^&]*)/gi,
				function(m, key, value) {
					vars[key] = value;
				});
		} catch (e) {
			Common.log(e);
		}
		return vars;
	}

	/**
	 * 记录信息
	 * @param {Object} data 要记录的数据
	 */
	Common.log = function(data) {
		try {
			if (data == undefined || data == null) {} else if (data.stack != undefined)
				console.log(data.stack);
			else
				console.log(data);
		} catch (e) {

		}
	}

	//--------------------------------
	if (window.Common == undefined) {
		try{  //iframe里调用会出错
			if (window.top.Common == undefined)
				window.Common = Common;
			else
				window.Common = window.top.Common;
		}catch(e){
			window.Common = Common;
		}
		
	}
	//--------------------------------
})(window);

String.prototype.padLeft = function(padChar, width) {
	var ret = this;
	while (ret.length < width) {
		if (ret.length + padChar.length < width) {
			ret = padChar + ret;
		} else {
			ret = padChar.substring(0, width - ret.length) + ret;
		}
	}
	return ret;
};

//--------------------------------全局设置
$(function() {
	//队列加载图片
	laterLoadImg('boboweb-laterLoadImg');
	//
	$.fn.limit = function() {
		var self = $("[limit]");
		self.each(function() {
			var objString = $(this).text();
			var objLength = $(this).text().length;
			var num = $(this).attr("limit");
			num = parseInt(num);
			if (objLength > num) {
				$(this).attr("title", objString);
				$(this).text(objString.substring(0, num) + "...");
			}
		})
	};
	$(document.body).limit();
	General.CheckIsWeixin(); //检查是否微信浏览器,如果是微信浏览器则隐藏标题

	//	alert(is_weixin());
	//--------------------滑动切换图片
	//	$("body").addClass('pt-page-moveFromRight');
	/*var mc = new Hammer($("header")[0]);
	mc.on("panleft", function(e) {
//		var $nextPage = $pages.eq( current ).addClass( 'pt-page-current' ),
//		var	outClass = '';
//		var inClass = '';
////
////		
//				outClass = 'pt-page-moveToLeft';
//				inClass = 'pt-page-moveFromRight';
////				$("body").addClass(outClass);
//				$("body").removeClass(inClass);
//				$("body").addClass(outClass);
//		console.log("left");
		history.go(1);
//		$('#image-list').carousel('next');
	});
	mc.on("panright", function(e) {
//		console.log("right");
				history.go(-1);
//		$('#image-list').carousel('prev');
	});*/
	//--------------------顶部菜单
	$("#toggle-top-menu").click(function() {
		$("#top-menu").toggleClass("none");
	});
	//	$("body").click(function(event) {
	$(document).click(function(event) {
		var mark = $(event.target).attr("mark");
		if (typeof(mark) === "undefined" || mark != "top-menu") {
			$("#top-menu").addClass("none"); //去掉头文件
		}
	});

	//--------------------判断是否有自动提交的表单
	if ($("form[data-submit=auto]").length > 0) {
		//点击"取消"按钮返回上一页
		$("form[data-submit=auto] button[data-action=return]").on("click", function(e) {
			General.stopEvent(e);
			window.history.go(-1);
		});
		//点击"有提交动作"的按钮提交数据
		$("form[data-submit=auto] button[data-action=submit]").on("click", function(e) {
			General.stopEvent(e);
			//获取提交地址
			var url = $(this).attr("data-href");
			var beforeAction = $(this).attr("data-before-ajax");
			var refreshTarget = $(this).attr("data-refresh");
			var tip = $(this).attr("data-tip");
			var isHideLoading = ($(this).attr("data-show-tip") == "false");
			var isHideResponse = ($(this).attr("data-show-response") == "false"); //是否隐藏弹出框
			var ignoreKey = $(this).attr("data-ignore"); //忽略的key
			var successFun = $(this).attr("data-success-function");
			if (successFun) {
				successFun = window[successFun];
			}

			var targetWin = window;
			if (refreshTarget == "parent")
				targetWin = window.parent;
			else if (refreshTarget == "parent.parent")
				targetWin = window.parent.parent;
			var mask = $(this).attr("data-mask");
			var maskWin = null;
			if (mask != undefined) {
				if (mask == "parent") {
					maskWin = window.parent;
					window.parent.General.showMask();
				} else if (mask == "parent.parent") {
					maskWin = window.parent.parent;
					window.parent.parent.General.showMask();
				} else {
					maskWin = window;
					General.showMask();
				}
			} else {

			}
			if (beforeAction) {
				//提交前的操作
				try {
					window[beforeAction]();
				} catch (e) {

				}
				//				return false;
			}
			//提交数据
			//			var str=$(this).closest("form").serialize();
			var data = General.getFormJson($(this).closest("form"));

			try {
				if (ignoreKey) {
					var keyArray = ignoreKey.split(":");
					data[keyArray[0]] = window[keyArray[1]];
				}
			} catch (e) {

			}
			Common.ajaxPostWantResult(url, data, tip, targetWin, maskWin, isHideLoading, successFun, this, isHideResponse);
			//			Common.ajaxPostWantResult(url, data, "", targetWin, maskWin);
		});
	}
	//--------------------判断是否有自动提交的ajax请求
	$("[data-auto='ajax']").on("click", function(e) {
		General.stopEvent(e);
		var url = $(this).attr("data-href");
		var beforeAction = $(this).attr("data-before-ajax");
		var refreshTarget = $(this).attr("data-refresh");
		var tip = $(this).attr("data-tip");
		var isHideLoading = ($(this).attr("data-show-tip") == "false");
		var isHideResponse = ($(this).attr("data-show-response") == "false"); //是否隐藏弹出框
		var ids = $(this).attr("data-submit-id");
		var successFun = $(this).attr("data-success-function");
		if (successFun) {
			successFun = window[successFun];
		}
		
		var params=this;
		
		//是否自动分页
		var isAutoPage = ($(this).attr("data-auto-page") == "true");
		var pageTarget = $(this).attr("data-page-table");
		try {
			if (isAutoPage) {
				var pageKey=ids;
				//判断是否有:号
				if(ids.indexOf(":")>=0){
					pageKey=ids.split(":")[0];
				}
				var page=General.getValue(pageKey);
				page=parseInt(page)+1;
				General.setValue(pageKey,page);
				params={
					pageTarget:pageTarget,
					target:this
				};
			}
		} catch (e) {

		}
		//刷新目标
		var targetWin = window;
		if (refreshTarget == "parent")
			targetWin = window.parent;
		else if (refreshTarget == "parent.parent")
			targetWin = window.parent.parent;
		//遮罩窗口	
		var mask = $(this).attr("data-mask");
		var maskWin = null;
		if (mask != undefined) {
			if (mask == "parent") {
				maskWin = window.parent;
				window.parent.General.showMask();
			} else if (mask == "parent.parent") {
				maskWin = window.parent.parent;
				window.parent.parent.General.showMask();
			} else {
				maskWin = window;
				General.showMask();
			}
		} else {

		}

		if (beforeAction) {
			//提交前的操作
			try {
				window[beforeAction]();
			} catch (e) {

			}
		}

		var data = {};
		//判断是否有附加参数
		if (ids) {
			var obj;
			$.each(ids.split(","), function(index, value) {
				obj = {};
				value=value+"";
				var key = value;
//				console.log(typeof value);
				var mustChangeName=value.indexOf(":")>=0;
				//判断是否有:号
				if(mustChangeName){
					var tempArray=value.split(":");
					value=tempArray[0];
					key=tempArray[1];
				}
//				console.log(key+":"+value);
				if (key.indexOf("#") == 0) {
					key = key.replace("#", "");
				} else if (key.indexOf(".") == 0) {
					key = key.replace(".", "");
				}
				data[key] = General.getValue(value);
			});
		}
		
		Common.ajaxPostWantResult(url, data, tip, targetWin, maskWin, isHideLoading, successFun, params, isHideResponse);
	});
	//--------------------点击时自动隐藏
	$("[data-auto-hide]").on("click", function(e) {
		$(this).addClass("hide");
	});
	//--------------------点击时自动显示目标
	$("[data-auto-target]").on("click", function(e) {
		General.stopEvent(e);
		//注：该方法被统一用来做分享的处理
		var isSharer=window.isSharer;
		var canShare=window.canShare;
		var isSubscribe=window.isSubscribe;
		if(isSubscribe==0){
			//您尚未关注商城公众号，无法成为分享客！
			$('#noAttentionTip1').modal();
			return;
		}
		if(canShare==2&&isSharer==0&&isSubscribe==1){
			//购买本商城任意商品后，即可成为分享客！
			$('#noAttentionTip2').modal();
			return;
		}
		
		var id = $(this).attr("data-auto-target");
		$(id).removeClass("hide");
	});
	//--------------------判断是否有提示(用于直接提交时的结果提示)
	if ($("#resultTip").length > 0) {
		var tipContent = General.getValue("#resultTip");
		General.alert(tipContent);
	}
	/*try {
		var currentFooterData = $("#footerMenuIndex");
		if (currentFooterData.length > 0) {
			var currentFooterIndex = parseInt(currentFooterData.val());
			$("#footer-menu li")[currentFooterIndex - 1].className = "active";
		}
	} catch (e) {

	}

	$("#footer-to-left").click(function() {
		$("#footer").animate({
			left: '-100%'
		});
		$("#footer-menu").animate({
			opacity: '0'
		});
	});
	$("#footer-to-right").click(function() {
		$("#footer").animate({
			left: '0'
		});
		$("#footer-menu").animate({
			opacity: '1'
		});
	});*/
	
      
});

